{% extends 'base/base.html' %}

{% block title %}{{ title }} - 多用户报警系统{% endblock %}

{% block content %}
<div class="container main-container">
    <div class="row mb-4">
        <div class="col-lg-12">
            <h1 class="page-title">{{ title }}</h1>
        </div>
    </div>
    
    <div class="row mb-4">
        <div class="col-lg-12">
            <div class="card">
                <div class="card-header">
                    <div class="row">
                        <div class="col-md-6">
                            <h3 class="card-title">任务执行日志详情</h3>
                        </div>
                        <div class="col-md-6 text-right">
                            <span class="badge badge-{% if log.is_success %}success{% else %}danger{% endif %}">
                                {% if log.is_success %}执行成功{% else %}执行失败{% endif %}
                            </span>
                        </div>
                    </div>
                </div>
                
                <div class="card-body">
                    <div class="mb-4">
                        <h4>基本信息</h4>
                        <table class="table table-bordered">
                            <tbody>
                                <tr>
                                    <th>任务名称</th>
                                    <td>{{ log.task.name }}</td>
                                    <th>执行状态</th>
                                    <td>
                                        {% if log.is_success %}
                                            <span class="badge badge-success">成功</span>
                                        {% else %}
                                            <span class="badge badge-danger">失败</span>
                                        {% endif %}
                                    </td>
                                </tr>
                                <tr>
                                    <th>开始时间</th>
                                    <td>{{ log.start_time|date:"Y-m-d H:i:s" }}</td>
                                    <th>结束时间</th>
                                    <td>
                                        {% if log.end_time %}
                                            {{ log.end_time|date:"Y-m-d H:i:s" }}
                                        {% else %}
                                            - 
                                        {% endif %}
                                    </td>
                                </tr>
                                <tr>
                                    <th>持续时间</th>
                                    <td>
                                        {% if log.duration %}
                                            {{ log.duration }}秒
                                        {% else %}
                                            - 
                                        {% endif %}
                                    </td>
                                    <th>尝试次数</th>
                                    <td>{{ log.attempt_count }}</td>
                                </tr>
                                {% if log.error_message %}
                                <tr>
                                    <th>错误信息</th>
                                    <td colspan="3">{{ log.error_message }}</td>
                                </tr>
                                {% endif %}
                            </tbody>
                        </table>
                    </div>
                    
                    <div class="mb-4">
                        <h4>执行日志</h4>
                        <div class="card card-body bg-light">
                            <pre class="whitespace-pre-wrap word-break">{{ log.log_content }}</pre>
                        </div>
                    </div>
                    
                    <div class="form-group text-center">
                        <a href="{% url 'tasks:task_execution_logs' %}" class="btn btn-secondary">
                            <i class="fa fa-arrow-left"></i> 返回日志列表
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}